package com.milo.xstream.outxml;

import com.milo.xstream.builder.AckBuilder;
import com.milo.xstream.xml.XStreamCDataConverter;
import com.milo.xstream.xml.XStreamTransformer;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;

import java.io.Serializable;

/**
 * 响应XML
 * @author milogenius
 * @date 2020/3/23 11:57
 *
 */
@XStreamAlias("xml")
@Data
public abstract class AlipayXmlOutMessage implements Serializable {
  private static final long serialVersionUID = -381382011286216263L;

  /**接受者userid*/
  @XStreamAlias("ToUserId")
  @XStreamConverter(value = XStreamCDataConverter.class)
  protected String toUserId;

  /**支付宝生活号appid*/
  @XStreamAlias("AppId")
  @XStreamConverter(value = XStreamCDataConverter.class)
  protected String appId;

  /**创建时间*/
  @XStreamAlias("CreateTime")
  protected Long createTime;

  /**消息类型*/
  @XStreamAlias("MsgType")
  @XStreamConverter(value = XStreamCDataConverter.class)
  protected String msgType;

  @XStreamAlias("response")
  protected Response response;

  @XStreamAlias("sign")
  protected String sign;

  @XStreamAlias("sign_type")
  protected String signType;

  /**
   * 获得ack builder
   * @return
   */
  public static AckBuilder ACK() {
    return new AckBuilder();
  }



  @SuppressWarnings("unchecked")
  public String toXml() {
    StringBuilder builder = new StringBuilder();
    String xml = XStreamTransformer.toXml((Class<AlipayXmlOutMessage>) this.getClass(), this);
    builder.append("<?xml version=\"1.0\" encoding=\"gbk\"?>\n");
    builder.append(xml);
    return builder.toString();
  }

}
